package kr.hkit.powerjava.chapter25.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.print.attribute.standard.Severity;

public class QuizClient {
	public static void main(String[] args) throws IOException {
		Socket quizeSocket = null;
		PrintWriter out = null;        //서버로 보내기 위한 출력 스트림
		BufferedReader in = null;     // t
		BufferedReader user = null;  //
		
		String serverMsg;
		String sendMsg;
		
		try {
			quizeSocket = new Socket("loaclhost", 5555);
			out =new PrintWriter(quizeSocket.getOutputStream(),true);
			in = new BufferedReader(new InputStreamReader(quizeSocket.getInputStream()));
			user = new BufferedReader(new InputStreamReader(System.in));
		} catch (UnknownHostException e) {
			System.err.println("localhost에 접근할수 없습니다");
			System.exit(-1);
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		while ((serverMsg = in.readLine()) !=null){
		System.out.println("서버 : "+serverMsg); //서버로 온 메세지
		if(serverMsg.equalsIgnoreCase("quit")){
			break;
		}
		sendMsg = user.readLine();
		if(sendMsg !=null){
			System.out.println("클라이언트 : "+ sendMsg);
			out.println(sendMsg);
		}
	}
		user.close();
		in.close();
		out.close();
		quizeSocket.close();
	}
}

